<template>
  <div class="analysis-container">
    <div class="header">
      <div class="back-btn" @click="goBack">
        <span class="icon">←</span> 返回班级
      </div>
      <h1>预警系统</h1>
    </div>
    <div class="warning-container">
      <div class="header">
        <h1>学习预警系统</h1>
        <div class="warning-stats">
          <div class="stat-card" v-for="stat in warningStats" :key="stat.type">
            <div class="stat-icon" :class="stat.level">{{ stat.icon }}</div>
            <div class="stat-info">
              <div class="stat-value">{{ stat.count }}</div>
              <div class="stat-label">{{ stat.label }}</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 预警学生列表 -->
      <div class="warning-list">
        <div class="list-header">
          <h2>预警学生名单</h2>
          <div class="filters">
            <select v-model="warningLevel">
              <option value="">全部等级</option>
              <option value="high">高风险</option>
              <option value="medium">中风险</option>
              <option value="low">低风险</option>
            </select>
          </div>
        </div>

        <div class="student-cards">
          <div v-for="student in warningStudents" :key="student.id" class="warning-card">
            <div class="student-basic">
              <div class="avatar">👤</div>
              <div class="info">
                <h3>{{ student.name }}</h3>
                <p>{{ student.class }}</p>
              </div>
              <div class="warning-level" :class="student.level">
                {{ student.levelText }}
              </div>
            </div>
            <div class="warning-details">
              <div class="detail-item" v-for="(value, key) in student.details" :key="key">
                <span class="label">{{ key }}</span>
                <span class="value" :class="value < 60 ? 'warning' : ''">{{ value }}</span>
              </div>
            </div>
            <div class="warning-actions">
              <button class="action-btn">发送通知</button>
              <button class="action-btn">查看详情</button>
            </div>
          </div>
        </div>
      </div>

      <!-- AI 建议 -->
      <div class="ai-suggestions">
        <h2>AI 干预建议</h2>
        <div class="suggestion-cards">
          <div v-for="(suggestion, index) in aiSuggestions" :key="index" class="suggestion-card">
            <div class="suggestion-icon">{{ suggestion.icon }}</div>
            <div class="suggestion-content">
              <h4>{{ suggestion.title }}</h4>
              <p>{{ suggestion.content }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

const goBack = () => {
  if (route.query.back) {
    router.push(route.query.back)
  } else {
    // 如果没有返回路径，则尝试构建
    const pathParts = route.path.split('/')
    const collegeId = pathParts[2]
    const gradeId = pathParts[4]
    const classId = pathParts[5]
    router.push(`/class/${collegeId}/${gradeId}/${classId}`)
  }
}

const warningLevel = ref('')

const warningStats = ref([
  { type: 'high', icon: '🔴', count: 15, label: '高风险', level: 'high' },
  { type: 'medium', icon: '🟡', count: 28, label: '中风险', level: 'medium' },
  { type: 'low', icon: '🟢', count: 45, label: '低风险', level: 'low' }
])

const warningStudents = ref([
  {
    id: 1,
    name: '张三',
    class: '计算机科学1班',
    level: 'high',
    levelText: '高风险',
    details: {
      '出勤率': 65,
      '作业完成率': 55,
      '测验成绩': 48,
      '课堂参与度': 40
    }
  },
  // ... 更多学生数据
])

const aiSuggestions = ref([
  {
    icon: '📊',
    title: '学习干预建议',
    content: '建议安排一对一辅导，重点关注数据结构和算法课程。'
  },
  {
    icon: '📅',
    title: '时间管理建议',
    content: '建议调整作息时间，增加早晨学习时段。'
  },
  {
    icon: '👥',
    title: '心理辅导建议',
    content: '建议进行心理疏导，帮助建立学习信心。'
  }
])
</script>

<style scoped>
.analysis-container {
  min-height: 100vh;
  background: #f0f2f5;
  padding: 30px;
}

.header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 30px;
}

.back-btn {
  padding: 10px 20px;
  background: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: #333;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.back-btn:hover {
  transform: translateX(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.warning-container {
  padding: 30px;
  background: #f5f6fa;
  min-height: 100vh;
}

.header {
  margin-bottom: 30px;
}

.header h1 {
  font-size: 28px;
  color: #333;
  margin-bottom: 20px;
}

.warning-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.stat-icon {
  font-size: 32px;
}

.stat-icon.high { color: #f5222d; }
.stat-icon.medium { color: #faad14; }
.stat-icon.low { color: #52c41a; }

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.stat-label {
  color: #666;
}

.warning-list {
  background: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 30px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.student-cards {
  display: grid;
  gap: 20px;
}

.warning-card {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
}

.student-basic {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.avatar {
  font-size: 32px;
  margin-right: 15px;
}

.warning-level {
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 14px;
  margin-left: auto;
}

.warning-level.high {
  background: #fff2f0;
  color: #f5222d;
  border: 1px solid #ffccc7;
}

.warning-level.medium {
  background: #fffbe6;
  color: #faad14;
  border: 1px solid #ffe58f;
}

.warning-level.low {
  background: #f6ffed;
  color: #52c41a;
  border: 1px solid #b7eb8f;
}

.warning-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
  margin-bottom: 15px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-item .value.warning {
  color: #f5222d;
}

.warning-actions {
  display: flex;
  gap: 10px;
}

.action-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #1890ff;
  color: white;
}

.ai-suggestions {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.suggestion-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.suggestion-card {
  display: flex;
  align-items: flex-start;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  gap: 15px;
}

.suggestion-icon {
  font-size: 24px;
}

.suggestion-content h4 {
  font-size: 18px;
  color: #333;
  margin-bottom: 8px;
}

.suggestion-content p {
  color: #666;
  line-height: 1.5;
}
</style> 